package org.d3_charset;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;

public class Test {
    public static void main(String[] args) throws UnsupportedEncodingException {
        //1.编码
        String data = "a我bc";
       byte[] bytes1 =  data.getBytes();
        System.out.println(Arrays.toString(bytes1));

        //.按照指定字符集进行编码
        byte[] bytes2 = data.getBytes("GBK");
        System.out.println(Arrays.toString(bytes2));

        //2.解码
        String s1 = new String(bytes1);//按照平台默认编码UTF-8
        System.out.println(s1);

        String s2 = new String(bytes2, "GBK");//按照平台默认编码UTF-8
        System.out.println(s2);//会出现乱码  在后面接上，"GBK"即可不会乱码

    }
}
